package cn.iocoder.yudao.module.tms.controller.admin.customerfollowlog;

import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.module.tms.controller.admin.customerfollowlog.vo.*;
import cn.iocoder.yudao.module.tms.dal.dataobject.customerfollowlog.CustomerFollowLogDO;
import cn.iocoder.yudao.module.tms.service.customerfollowlog.CustomerFollowLogService;

@Tag(name = "管理后台 - 客户跟进日志")
@RestController
@RequestMapping("/tms/customer-follow-log")
@Validated
public class CustomerFollowLogController {

    @Resource
    private CustomerFollowLogService customerFollowLogService;

    @PostMapping("/create")
    @Operation(summary = "创建客户跟进日志")
    @PreAuthorize("@ss.hasPermission('tms:customer-follow-log:create')")
    public CommonResult<Long> createCustomerFollowLog(@Valid @RequestBody CustomerFollowLogSaveReqVO createReqVO) {
        return success(customerFollowLogService.createCustomerFollowLog(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新客户跟进日志")
    @PreAuthorize("@ss.hasPermission('tms:customer-follow-log:update')")
    public CommonResult<Boolean> updateCustomerFollowLog(@Valid @RequestBody CustomerFollowLogSaveReqVO updateReqVO) {
        customerFollowLogService.updateCustomerFollowLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除客户跟进日志")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('tms:customer-follow-log:delete')")
    public CommonResult<Boolean> deleteCustomerFollowLog(@RequestParam("id") Long id) {
        customerFollowLogService.deleteCustomerFollowLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得客户跟进日志")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('tms:customer-follow-log:query')")
    public CommonResult<CustomerFollowLogRespVO> getCustomerFollowLog(@RequestParam("id") Long id) {
        CustomerFollowLogDO customerFollowLog = customerFollowLogService.getCustomerFollowLog(id);
        return success(BeanUtils.toBean(customerFollowLog, CustomerFollowLogRespVO.class));
    }

    @GetMapping("/list-by-follow-up")
    @Operation(summary = "根据跟进记录ID获取日志列表")
    @Parameter(name = "followUpId", description = "跟进记录ID", required = true)
    @PreAuthorize("@ss.hasPermission('tms:customer-follow-log:query')")
    public CommonResult<List<CustomerFollowLogRespVO>> getCustomerFollowLogListByFollowUpId(@RequestParam("followUpId") Long followUpId) {
        List<CustomerFollowLogDO> list = customerFollowLogService.getCustomerFollowLogListByFollowUpId(followUpId);
        return success(BeanUtils.toBean(list, CustomerFollowLogRespVO.class));
    }

    @GetMapping("/list-by-company")
    @Operation(summary = "根据公司ID获取日志列表")
    @Parameter(name = "companyId", description = "公司ID", required = true)
    @PreAuthorize("@ss.hasPermission('tms:customer-follow-log:query')")
    public CommonResult<List<CustomerFollowLogRespVO>> getCustomerFollowLogListByCompanyId(@RequestParam("companyId") Long companyId) {
        List<CustomerFollowLogDO> list = customerFollowLogService.getCustomerFollowLogListByCompanyId(companyId);
        return success(BeanUtils.toBean(list, CustomerFollowLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得客户跟进日志分页")
    @PreAuthorize("@ss.hasPermission('tms:customer-follow-log:query')")
    public CommonResult<PageResult<CustomerFollowLogRespVO>> getCustomerFollowLogPage(@Valid CustomerFollowLogPageReqVO pageReqVO) {
        PageResult<CustomerFollowLogDO> pageResult = customerFollowLogService.getCustomerFollowLogPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CustomerFollowLogRespVO.class));
    }

}
